#!/bin/env bash

#Describe: This file is used to set nic soft interrupt
#Author: Edward, Hex
#Date: 2019-07-01

function stop_irqbalance
{
	service irqbalance start > /dev/null 2>&1
#	sleep 1
	service irqbalance stop > /dev/null 2>&1
}

function set_nic_soft_interrupt
{
	ip_cmd=`which ip`
	cpu_num=`lscpu | grep "^CPU(s):" | awk '{print $2}'`
	irqs=`${ip_cmd} a | awk -F':' '{sub(/^[[:blank:]]*/,"",$2);print $2}' | xargs -i grep {}- /proc/interrupts | cut -d':' -f1`
	num=0
	for irq in $irqs;do
		echo $num > /proc/irq/$irq/smp_affinity_list
		#echo "$num > /proc/irq/$irq/smp_affinity_list"
		let num++
		[ $num -eq $cpu_num ] && num=0
	done
}

stop_irqbalance
set_nic_soft_interrupt

echo "set nic si success."

exit 0
